<template>
   <div class="app-container">
      <el-row :gutter="20">
         <!--数据-->
         <el-col>
            <el-row>
               <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
                  <el-form-item label="机台" prop="machine_data">
                     <el-select
                        v-model="queryParams.mId"
                        placeholder="机台"
                        clearable
                        style="width: 240px"
                     >
                        <el-option
                           v-for="one in machinesInfo"
                           :key="one.id"
                           :label="one.machine_info"
                           :value="one.id"
                        />
                     </el-select>
                  </el-form-item>
                  <el-form-item label="客户端上传时间" style="width: 308px;" label-width="120px">
                     <el-date-picker
                        v-model="dateRange"
                        value-format="YYYY-MM-DD"
                        type="daterange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                     ></el-date-picker>
                  </el-form-item>
                  <el-form-item>
                     <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                  </el-form-item>
               </el-form>
               <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
            </el-row>
            <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
               <el-table-column type="selection" width="50" align="center" />
               <el-table-column label="机台号" align="center" key="machine_id" prop="machine_id" v-if="columns[0].visible" :show-overflow-tooltip="true" />
               <el-table-column label="客户端上传时间" align="center" key="CurTimel" prop="CurTimel" v-if="columns[1].visible" :show-overflow-tooltip="true">
                  <template #default="scope">
                     <span>{{ formatDateRemoveLetterT(scope.row.CurTimel) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="总进分数" align="center" key="TotalInNum" prop="TotalInNum" v-if="columns[2].visible" :show-overflow-tooltip="true" />
               <el-table-column label="总退分数" align="center" key="TotalOutNum" prop="TotalOutNum" v-if="columns[3].visible" :show-overflow-tooltip="true" />
               <el-table-column label="进退金额百分比" align="center" key="CurInOutBFB" prop="CurInOutBFB" v-if="columns[4].visible" :show-overflow-tooltip="true" />
               <el-table-column label="总玩金额" align="center" key="TotalPlayFNum" prop="TotalPlayFNum" v-if="columns[5].visible" :show-overflow-tooltip="true" />
               <el-table-column label="总赢金额" align="center" key="TotalWinFNum" prop="TotalWinFNum" v-if="columns[6].visible" :show-overflow-tooltip="true" />
               <el-table-column label="总玩金额与总赢金额百分比" align="center" key="CurPlayOrWinBFB" prop="CurPlayOrWinBFB" v-if="columns[7].visible" :show-overflow-tooltip="true" />
               <el-table-column label="总玩次数" align="center" key="TotalPlayCNum" prop="TotalPlayCNum" v-if="columns[8].visible" :show-overflow-tooltip="true" />
               <el-table-column label="总赢次数" align="center" key="TotalWinCNum" prop="TotalWinCNum" v-if="columns[9].visible" :show-overflow-tooltip="true" />
               <el-table-column label="总玩次数与总赢次数百分比" align="center" key="CurPlayCountOrWinCount" prop="CurPlayCountOrWinCount" v-if="columns[10].visible" :show-overflow-tooltip="true" />
               <el-table-column label="上期记录时间" align="center" key="LastTimel" prop="LastTimel" v-if="columns[11].visible" :show-overflow-tooltip="true">
                  <template #default="scope">
                     <span>{{ formatDateRemoveLetterT(scope.row.LastTimel) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="上期总进分数" align="center" key="LastTotalInNum" prop="LastTotalInNum" v-if="columns[12].visible" :show-overflow-tooltip="true" />
               <el-table-column label="上期总退分数" align="center" key="LastTotalOutNum" prop="LastTotalOutNum" v-if="columns[13].visible" :show-overflow-tooltip="true" />
               <el-table-column label="上期进退分数百分比" align="center" key="LastInOutBFB" prop="LastInOutBFB" v-if="columns[14].visible" :show-overflow-tooltip="true" />
               <el-table-column label="上期总玩分数" align="center" key="LastTotalPlayFNum" prop="LastTotalPlayFNum" v-if="columns[15].visible" :show-overflow-tooltip="true" />
               <el-table-column label="上期总赢分数" align="center" key="LastTotalWinFNum" prop="LastTotalWinFNum" v-if="columns[16].visible" :show-overflow-tooltip="true" />
               <el-table-column label="上期总赢分数总玩分数百分比" align="center" key="LastPlayOrWinBFB" prop="LastPlayOrWinBFB" v-if="columns[17].visible" :show-overflow-tooltip="true" />
               <el-table-column label="上期总玩次数" align="center" key="LastTotalPlayCNum" prop="LastTotalPlayCNum" v-if="columns[18].visible" :show-overflow-tooltip="true" />
               <el-table-column label="上期总赢次数" align="center" key="LastTotalWinOrPlayCNum" prop="LastTotalWinOrPlayCNum" v-if="columns[19].visible" :show-overflow-tooltip="true" />
               <el-table-column label="创建时间" align="center" prop="addTime" v-if="columns[20].visible" width="160">
                  <template #default="scope">
                     <span>{{ parseTime(scope.row.addTime) }}</span>
                  </template>
               </el-table-column>
            </el-table>
            <pagination
               v-show="total > 0"
               :total="total"
               v-model:page="queryParams.pageNum"
               v-model:limit="queryParams.pageSize"
               @pagination="getList"
            />
         </el-col>
      </el-row>
   </div>
</template>

<script setup name="Machine">
import { listData, machineSelect } from "@/api/game/business";
import { formatDateRemoveLetterT } from "@/utils/index";

const { proxy } = getCurrentInstance();

const dataList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const machinesInfo = ref(undefined);
const dateRange = ref([]);

// 列显隐信息
const columns = ref([
  { key: 0, label: `机器id`, visible: true },
  { key: 1, label: `客户端上传时间`, visible: true },
  { key: 2, label: `总进分数`, visible: true },
  { key: 3, label: `总退分数`, visible: true },
  { key: 4, label: `进退金额百分比`, visible: true },
  { key: 5, label: `总玩金额`, visible: true },
  { key: 6, label: `总赢金额`, visible: true },
  { key: 7, label: `总玩金额与总赢金额百分比`, visible: true },
  { key: 8, label: `总玩次数`, visible: true },
  { key: 9, label: `总赢次数`, visible: true },
  { key: 10, label: `总玩次数与总赢次数百分比`, visible: true },
  { key: 11, label: `上期记录时间`, visible: false },
  { key: 12, label: `上期总进分数`, visible: false },
  { key: 13, label: `上期总退分数`, visible: false },
  { key: 14, label: `上期进退分数百分比`, visible: false },
  { key: 15, label: `上期总玩分数`, visible: false },
  { key: 16, label: `上期总赢分数`, visible: false},
  { key: 17, label: `上期总赢分数总玩分数百分比`, visible: false },
  { key: 18, label: `上期总玩次数`, visible: false },
  { key: 19, label: `上期总赢次数`, visible: false },
  { key: 20, label: `创建时间`, visible: true }
]);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    mId: undefined,
  }
});

const { queryParams } = toRefs(data);

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
};

/** 选择条数  */
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
//   console.log("handleSelectionChange",ids)
};
/** 查询列表 */
function getList() {
  loading.value = true;
//   console.log("queryParams.value")
//   console.log(queryParams.value)
  listData(proxy.addDateRange(queryParams.value, dateRange.value)).then(res => {
    console.log(res)
    loading.value = false;
    dataList.value = res.rows;
    total.value = res.total;
  });
};
/** 查询机台下拉列表 */
function getMachineSelect() {
   machineSelect().then(response => {
    console.log(response)
    machinesInfo.value = response.data;
  });
};
getList();
getMachineSelect();

</script>
